package com.link.base.base.dingtalk.service;

import com.alibaba.fastjson.JSONArray;
import com.link.base.core.basic.util.DingDingUtil;
import com.link.core.util.PropertyUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class DingTalkServiceImpl implements DingTalkService {
    @Override
    public Map<String, Object> getDingConfig(String url, JSONArray jsApiList) throws Exception {
        Map<String,Object> result = new HashMap<>();
        //获取jsapi_ticket
        String ticket = DingDingUtil.getJsapiTicket("",url);

        String nonceStr = DingDingUtil.getRandomStr(16);
        long currentTimeMillis = System.currentTimeMillis();
        String signStr = DingDingUtil.sign(ticket,nonceStr,currentTimeMillis,url);

        String agentId = PropertyUtil.getCommonProperty("dingAgentId");
        result.put("agentId",agentId);
        String corpId = PropertyUtil.getCommonProperty("dingCorpId");
        result.put("corpId",corpId);
        result.put("timeStamp",currentTimeMillis);
        result.put("signature",signStr);
        result.put("nonceStr",nonceStr);
        result.put("jsApiList",jsApiList);
        return result;
    }
}
